package de.fstyle.test.spring.property.source.order;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration.Dynamic;

import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

public class PropertyWebApplicationInitializer implements WebApplicationInitializer {

	public void onStartup(ServletContext servletContext)
	throws ServletException {
		
		// context
		
		AnnotationConfigWebApplicationContext context = 
				new AnnotationConfigWebApplicationContext();
		
		context.register(PropertiesA.class);
		context.register(PropertiesB.class);
		context.register(PropertiesC.class);
		context.register(PropertiesD.class);
		
		context.register(PropertySourceClassConfigurer.class);
		context.setServletContext(servletContext);

		// servlet
		
		Dynamic servlet = servletContext.addServlet(
				"dispatcher",
				new DispatcherServlet(context));
		servlet.addMapping("/");
		servlet.setLoadOnStartup(1);

	}

}
